home *** CD-ROM | disk | FTP | other *** search
Visual Basic class definition | 1999-08-31 | 18.5 KB | 582 lines |
- VERSION 1.0 CLASS
- BEGIN
- MultiUse = -1 'True
- Persistable = 0 'NotPersistable
- DataBindingBehavior = 0 'vbNone
- DataSourceBehavior = 0 'vbNone
- MTSTransactionMode = 0 'NotAnMTSObject
- END
- Attribute VB_Name = "clsScreen"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = True
- Attribute VB_PredeclaredId = False
- Attribute VB_Exposed = False
- Option Explicit
-
- 'Constants
- Const MyModule = "clsScreen"
-
- 'Hooked Variables - for every one you add, add it to class_terminate as well
- Public WithEvents mForm As Form
- Attribute mForm.VB_VarHelpID = -1
- Private WithEvents mToolbar As Toolbar
- Attribute mToolbar.VB_VarHelpID = -1
- Private mStatusBar As StatusBar
- Attribute mStatusBar.VB_VarHelpID = -1
- Private WithEvents mLstPlayers As ListBox
- Attribute mLstPlayers.VB_VarHelpID = -1
- Private WithEvents mLstGMs As ListBox
- Attribute mLstGMs.VB_VarHelpID = -1
- Private WithEvents mPicLights As PictureBox
- Attribute mPicLights.VB_VarHelpID = -1
- Private WithEvents mTxtInput As TextBox
- Attribute mTxtInput.VB_VarHelpID = -1
-
- Friend Sub Init()
- '------------------------------------------------------------
- 'Initialize the screen settings
- '------------------------------------------------------------
- Const MyError = MyModule & "_" & "Init"
- If Timings Then PerformanceStartTime MyError
- On Error GoTo Err_Init
-
- '------------------------------------------------------------
- 'Hook the form to capture its events
- '------------------------------------------------------------
- Load frmServer
- Set mForm = frmServer
- mForm_Load
- 'mForm.ControlBox = False
-
- '------------------------------------------------------------
- 'Initialize the toolbar
- '------------------------------------------------------------
-
- Set mToolbar = mForm.Toolbar1
- mToolbar.ImageList = mForm.imgListToolbar
- mToolbar.Appearance = ccFlat
- mToolbar.Wrappable = True
- mToolbar.AllowCustomize = False
- mToolbar.RestoreToolbar "Incarnation Server", "Settings", "mToolbar"
-
- With mToolbar.Buttons
- .Add , "Upload", "Upload Client", , "Upload"
- .Add , "Record", "Record", , "Microphone"
- .Add , "PlaySound", "Play", , "Sound"
- .Add , "Time", "Time", , "Time"
- .Add , "Weather", "Weather", , "Sun"
- .Add , "Sessions", "Sessions", , "Sessions"
- .Add , "Timings", "Timings", , "Timings"
- .Add , "Monsters", "Spawning", , "Hamster"
- .Add , "Warning", "Warning", , "Warning"
- .Add , "Quit", "Shutdown", , "Stop"
- End With
-
- 'Set up sub-buttons.
- With mToolbar.Buttons(3)
- .Style = tbrDropdown
- .ButtonMenus.Add , "Recorded", "Recorded Message"
- .ButtonMenus.Add , "Midi1", "Midi 1"
- .ButtonMenus.Add , "Welcome", "Welcome"
- End With
-
- With mToolbar.Buttons(4)
- .Style = tbrDropdown
- .ButtonMenus.Add , , "Midnight"
- .ButtonMenus.Add , , "01:00 AM"
- .ButtonMenus.Add , , "02:00 AM"
- .ButtonMenus.Add , , "03:00 AM"
- .ButtonMenus.Add , , "04:00 AM"
- .ButtonMenus.Add , , "05:00 AM"
- .ButtonMenus.Add , , "06:00 AM"
- .ButtonMenus.Add , , "07:00 AM"
- .ButtonMenus.Add , , "08:00 AM"
- .ButtonMenus.Add , , "09:00 AM"
- .ButtonMenus.Add , , "10:00 AM"
- .ButtonMenus.Add , , "12:00 AM"
- .ButtonMenus.Add , , "Noon"
- .ButtonMenus.Add , , "01:00 PM"
- .ButtonMenus.Add , , "02:00 PM"
- .ButtonMenus.Add , , "03:00 PM"
- .ButtonMenus.Add , , "04:00 PM"
- .ButtonMenus.Add , , "05:00 PM"
- .ButtonMenus.Add , , "06:00 PM"
- .ButtonMenus.Add , , "07:00 PM"
- .ButtonMenus.Add , , "08:00 PM"
- .ButtonMenus.Add , , "09:00 PM"
- .ButtonMenus.Add , , "10:00 PM"
- .ButtonMenus.Add , , "11:00 PM"
- End With
-
- With mToolbar.Buttons(5)
- .Style = tbrDropdown
- .ButtonMenus.Add , "Sun", "Sun"
- .ButtonMenus.Add , "Rain", "Rain"
- .ButtonMenus.Add , "Snow", "Snow"
- End With
-
- With mToolbar.Buttons(7)
- .Style = tbrDropdown
- .ButtonMenus.Add , "Display", "Display To Screen"
- .ButtonMenus.Add , "File", "Write To File"
- .ButtonMenus.Add , , "-"
- .ButtonMenus.Add , "TurnOn", "Turn On Timings"
- .ButtonMenus.Add , "TurnOff", "Turn Off Timings"
- End With
-
- '------------------------------------------------------------
- 'Initialize the status bar
- '------------------------------------------------------------
- Set mStatusBar = mForm.StatusBar1
- With mStatusBar
- .Panels.Clear
- .Panels.Add , "pnl1"
- .Panels.Add , "pnl2"
- .Panels.Add , "pnlTime"
- Time = G.CurrentTime
- End With
-
- '------------------------------------------------------------
- 'Initialize the player list
- '------------------------------------------------------------
- Set mLstPlayers = mForm.lstPlayers
- Set mLstGMs = mForm.lstGMs
- mLstPlayers.Visible = True
- mLstGMs.Visible = False
-
- '------------------------------------------------------------
- 'Initialize the flashing lights
- '------------------------------------------------------------
- Set mPicLights = mForm.picLights
- mPicLights.Width = 505
- mPicLights.Height = 100
- 'mPicLights.DrawWidth = 4
- mPicLights.FillStyle = 0
-
- '------------------------------------------------------------
- 'Rearrange the controls on the form
- '------------------------------------------------------------
- mForm_Resize
-
- '------------------------------------------------------------
- 'Initialize the input box
- '------------------------------------------------------------
- Set mTxtInput = mForm.txtInput
-
- '------------------------------------------------------------
- 'Show the form
- '------------------------------------------------------------
- mForm.Visible = True
-
- '------------------------------------------------------------
- 'End of procedure
- '------------------------------------------------------------
- If Timings Then PerformanceEndTime MyError
- Exit Sub
-
- Err_Init:
- CScreen.DebugText = MyError & ": " & Err.Number & " - " & Err.Description
- Resume Next
- End Sub
-
- Friend Property Let DebugText(ByVal s As String)
- '------------------------------------------------------------
- 'Writes text to the server debug display
- '------------------------------------------------------------
-
- Dim chars As Long
- Const MyError = MyModule & "_" & "DebugText"
- If Timings Then PerformanceStartTime MyError
-
- On Error GoTo Err_Init
-
- If Right$(s, 2) = vbCrLf Then
- 'skip it
- Else
- s = s & vbCrLf
- End If
-
- 'Update server debug display
- With mForm.txtDebug
- chars = Len(.Text)
- If chars > 15000 Then
- .Text = Right(.Text, 1000)
- chars = Len(.Text)
- End If
- If Len(s) > 15000 Then
- s = Right(s, 15000)
- End If
- .SelStart = chars
- .SelText = Format(Now) & " " & s
- .SelStart = Len(.Text)
- End With
-
- If Timings Then PerformanceEndTime MyError
- Exit Property
-
- Err_Init:
- Debug.Print Err.Number & " - " & Err.Description
- Resume Next
- End Property
-
- Friend Property Let OutputText(ByVal s As String)
- '------------------------------------------------------------
- 'Writes text to the server output display
- '------------------------------------------------------------
-
- Dim chars As Long
- Const MyError = MyModule & "_" & "OutputText"
- If Timings Then PerformanceStartTime MyError
-
- On Error GoTo Err_Init
-
- If Right$(s, 2) = vbCrLf Then
- 'skip it
- Else
- s = s & vbCrLf
- End If
-
- 'Update server debug display
- With mForm.txtOutput
- chars = Len(.Text)
- If chars > 100000 Then
- .Text = ""
- chars = 0
- '.Text = Right(.Text, 1000)
- 'chars = Len(.Text)
- End If
- If Len(s) > 80000 Then
- s = Right(s, 80000)
- End If
- .SelStart = chars
- .SelText = Format(Now) & " " & s
- .SelStart = Len(.Text)
- End With
-
- If Timings Then PerformanceEndTime MyError
- Exit Property
-
- Err_Init:
- CScreen.DebugText = MyError & ": " & Err.Number & " - " & Err.Description
- Resume Next
- End Property
-
- Friend Property Let Time(ByVal t As Date)
- '------------------------------------------------------------
- 'Updates the date/time display
- '------------------------------------------------------------
-
- Const MyError = MyModule & "_" & "Time"
- If Timings Then PerformanceStartTime MyError
-
- On Error GoTo Err_Init
-
- mStatusBar.Panels("pnlTime").Text = Format(t, "HH:MM AMPM")
-
- If Timings Then PerformanceEndTime MyError
- Exit Property
-
- Err_Init:
- CScreen.DebugText = MyError & ": " & Err.Number & " - " & Err.Description
- Resume Next
- End Property
-
- Private Sub Class_Terminate()
- '------------------------------------------------------------
- 'Shuts down the screen class
- '------------------------------------------------------------
-
- 'Release all hooked variables
- Unload mForm
- Set mForm = Nothing
- Set mToolbar = Nothing
- Set mStatusBar = Nothing
- Set mLstPlayers = Nothing
- Set mLstGMs = Nothing
- Set mPicLights = Nothing
- Set mTxtInput = Nothing
- End Sub
-
- Private Sub mForm_Load()
- '------------------------------------------------------------
- 'Set up tcp callback
- '------------------------------------------------------------
- TCP.StartCallback
- End Sub
-
- Private Sub mForm_Unload(Cancel As Integer)
- '------------------------------------------------------------
- 'Make sure they quit from the 'shutdown' button only, and
- 'if so, disconnect the TCP callbacks
- '------------------------------------------------------------
- If QuitGame = False Then
- 'don't let them click the x!
- MsgBox "Please quit by clicking the 'shutdown' button"
- Cancel = 1
- Else
- TCP.StopCallback
- End If
- End Sub
-
- Private Sub mForm_Resize()
- '------------------------------------------------------------
- 'Resize all controls on form
- '------------------------------------------------------------
- Dim NewHeight As Long
- Dim NewWidth As Long
- Dim HeightLeft As Long
- Dim WidthLeft As Long
- Dim ToolbarHeight As Long
- Const MyError = MyModule & "_" & "mForm_Resize"
- If Timings Then PerformanceStartTime MyError
- On Error GoTo Err_Init
-
- 'Display the current width/height
- mStatusBar.Panels("pnl2").Text = mForm.ScaleWidth & "x" & mForm.ScaleHeight
-
- 'Set the minimum height/width of the form
- NewHeight = mForm.ScaleHeight
- NewWidth = mForm.ScaleWidth
- If NewWidth < 400 Then
- mForm.Width = 6120
- Exit Sub
- End If
- If NewHeight < 350 Then
- mForm.Height = 5655
- Exit Sub
- End If
-
- 'Figure out the toolbar height
- If NewWidth < 752 Then
- ToolbarHeight = 108
- Else
- ToolbarHeight = 56
- End If
-
- 'Size the flashing lights
- With mPicLights
- .Top = ToolbarHeight
- .Left = 0
- End With
-
- 'Calculate what's left
- HeightLeft = NewHeight - (mPicLights.Top + mPicLights.Height) - (mForm.txtInput.Height) - (mForm.StatusBar1.Height)
- WidthLeft = NewWidth - mPicLights.Width
-
- 'Set the player and gm limStatusBarox colors
- mLstPlayers.BackColor = vbBlack
- mLstGMs.BackColor = vbBlack
- mLstPlayers.ForeColor = &HFFC0C0
- mLstGMs.ForeColor = &H1080F0
- 'Set the player and gm top and height
- mLstPlayers.Top = ToolbarHeight
- mLstGMs.Top = ToolbarHeight
- mLstPlayers.Height = mPicLights.Height
- mLstGMs.Height = mPicLights.Height
- If WidthLeft > 140 Then
- 'display player and gm list
- mLstGMs.Visible = True
- mLstPlayers.Width = WidthLeft / 2
- mLstPlayers.Left = mPicLights.Width
- mLstGMs.Width = NewWidth - (mLstPlayers.Left + mLstPlayers.Width)
- mLstGMs.Left = mLstPlayers.Left + mLstPlayers.Width
- ElseIf WidthLeft > 0 Then
- 'display player list only
- mLstGMs.Visible = False
- mLstPlayers.Width = WidthLeft
- mLstPlayers.Left = mPicLights.Width
- Else
- 'don't even bother.
- End If
-
- 'Size the debug textbox
- With mForm.txtDebug
- .BackColor = vbBlack
- .Height = HeightLeft * 0.2
- .Top = mPicLights.Top + mPicLights.Height
- .Left = 0
- .Width = NewWidth
- End With
-
- 'Size the input textbox
- With mForm.txtInput
- .BackColor = &HFFFFFF
- .Top = mForm.txtDebug.Top + mForm.txtDebug.Height
- .Left = 0
- .Width = NewWidth
- End With
-
- 'Size the output textbox
- With mForm.txtOutput
- .BackColor = &HC0C0C0
- .Height = HeightLeft * 0.8
- .Top = mForm.txtInput.Top + mForm.txtInput.Height
- .Left = 0
- .Width = NewWidth
- End With
-
- 'Size the status bar
- With mForm.StatusBar1
- .Panels("pnl2").Width = 70
- .Panels("pnlTime").Width = 70
- .Panels("pnl1").Width = NewWidth - .Panels("pnl2").Width - .Panels("pnlTime").Width
- End With
-
- If Timings Then PerformanceEndTime MyError
- Exit Sub
-
- Err_Init:
- If Err.Number = 91 Then
- 'the form isn't ready to be sized yet - exit
- Exit Sub
- Else
- CScreen.DebugText = MyError & ": " & Err.Number & " - " & Err.Description
- Resume Next
- End If
- End Sub
-
- Private Sub mPicLights_MouseMove(Button As Integer, Shift As Integer, x As Single, Y As Single)
- '------------------------------------------------------------
- 'Displays the session the user is currently hovering over
- '------------------------------------------------------------
- Dim x1 As Long, y1 As Long
- Dim Index As Long
- Dim Status As Long, s As String
- Const MyError = MyModule & "_" & "mPicLights"
- If Timings Then PerformanceStartTime MyError
- On Error GoTo Err_Init
-
- '500 wide by 100 tall - convert down to 100 wide by 20 tall
- y1 = CInt(Y \ 5) + 1 'use the backwards \ to discard remainder
- x1 = CInt(x \ 5) + 1
- Index = (y1 - 1) * 100 + x1
- Status = Connection(Index).Status
- Select Case Status
- Case ltDisconnected: s = "ltDisconnected"
- Case ltIdle: s = "ltIdle"
- Case ltTCPUnspecifiedWriteError: s = "ltTCPUnspecifiedWriteError"
- Case ltTCPReadError: s = "ltTCPReadError"
- Case ltTCPSendError: s = "ltTCPSendError"
- Case ltTCPSendTextError: s = "ltTCPSendTextError"
- Case ltTCPBlocked: s = "ltTCPBlocked"
- End Select
-
- mPicLights.ToolTipText = "Session " & Index & " " & Connection(Index).Name & " - " & s
- If Timings Then PerformanceEndTime MyError
- Exit Sub
-
- Err_Init:
- CScreen.DebugText = MyError & ": " & Err.Number & " - " & Err.Description
- Resume Next
- End Sub
-
- Private Sub mToolbar_ButtonClick(ByVal Button As MSComctlLib.Button)
- '------------------------------------------------------------
- 'Process the toolbar button commands
- '------------------------------------------------------------
- Dim btn As String
- Const MyError = MyModule & "_" & "mToolbar_ButtonClick"
- If Timings Then PerformanceStartTime MyError
- On Error GoTo Err_Init
-
- btn = LCase(Button.Caption)
- If btn = "time" Then
- 'set the server time
- G.CurrentTime = Now
- ElseIf btn = "timings" Then
- 'send 'display to screen' mouseclick
- mToolbar_ButtonMenuClick Button.ButtonMenus("Display")
- ElseIf btn = "shutdown" Then
- 'shut the program down
- QuitGame = True
- GameShutDown
- Else
- MsgBox Button.Caption
- End If
-
- If Timings Then PerformanceEndTime MyError
- Exit Sub
-
- Err_Init:
- CScreen.DebugText = MyError & ": " & Err.Number & " - " & Err.Description
- Resume Next
- End Sub
-
- Private Sub mToolbar_ButtonMenuClick(ByVal ButtonMenu As MSComctlLib.ButtonMenu)
- '------------------------------------------------------------
- 'Process the toolbar menu commands
- '------------------------------------------------------------
- Dim Parent As String, Menu As String
- Const MyError = MyModule & "_" & "mToolbar_ButtonMenuClick"
- 'If Timings Then PerformanceStartTime MyError
- On Error GoTo Err_Init
-
- Parent = LCase(ButtonMenu.Parent.Caption)
- Menu = LCase(ButtonMenu.Text)
-
- If Parent = "time" Then
- If Menu = "midnight" Then
- G.CurrentTime = CDate("12:00 am")
- ElseIf Menu = "noon" Then
- G.CurrentTime = CDate("12:00 pm")
- Else
- G.CurrentTime = CDate(Menu)
- End If
- ElseIf Parent = "timings" Then
- If Menu = "display to screen" Then
- CScreen.OutputText = Perf.List()
- ElseIf Menu = "turn on timings" Then
- Timings = True
- ElseIf Menu = "turn off timings" Then
- Timings = False
- Else
- MsgBox Parent & " - " & Menu
- End If
- Else
- MsgBox Parent & " - " & Menu
- End If
-
- 'If Timings Then PerformanceEndTime MyError
- Exit Sub
-
- Err_Init:
- CScreen.DebugText = MyError & ": " & Err.Number & " - " & Err.Description
- Resume Next
- End Sub
-
- Private Sub mTxtInput_KeyPress(KeyAscii As Integer)
- '------------------------------------------------------------
- 'Send data from the server as 'sysop'
- '------------------------------------------------------------
-
- Const MyError = MyModule & "_" & "mTxtInput_KeyPress"
- If Timings Then PerformanceStartTime MyError
- On Error GoTo Err_Init
- Dim StrData As String
-
- If KeyAscii = 13 Then
- StrData = mTxtInput.Text
- mTxtInput.Text = ""
- TCP.SendText StrData, 0
- End If
-
- If Timings Then PerformanceEndTime MyError
- Exit Sub
-
- Err_Init:
- CScreen.DebugText = MyError & ": " & Err.Number & " - " & Err.Description
- Resume Next
- End Sub
-
- Friend Property Let Lights(Index As Long, LightState As enumLights)
- '------------------------------------------------------------
- 'Turns on/off a flashing light.
- 'Lights are 100 across by 20 down.
- '------------------------------------------------------------
- Dim x As Long, Y As Long
- Y = (CInt((Index - 1) \ 100) + 1) 'use the backwards \ to discard remainder
- x = (Index - ((Y - 1) * 100))
- mPicLights.Line ((x - 1) * 5, (Y - 1) * 5)-(((x - 1) * 5) + 3, ((Y - 1) * 5) + 3), LightState, BF
- mPicLights.Refresh
- End Property
-